package com.tarena.luban.sentinel.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.stereotype.Service;

@Service
public class HelloService implements HelloApi{
    @SentinelResource(value="sayHi",blockHandler = "blockHandler")
    public String sayHi(String name) {
        int a=1/0;
//        try {
//            Thread.sleep(1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        String result="hi "+name;
        return result;
    }
    //对于sentinel规则限制的资源,处理访问的降级逻辑
    public String blockHandler(String name, BlockException e) {
        return "对不起"+name+",限流规则起作用了";
    }
}
